#ifndef     __MOTOR_DRV_H
#define     __MOTOR_DRV_H

#include <stdint.h>
#include "../utils/object.h"
#include "../utils/no_copyable.h"
#include "../rtos/mutex.h"

namespace driver {

class MotorDrv : utils::no_copyable_t {

public:
    MotorDrv();

    void reset();

    void sleep();
    void wake_up();

    static constexpr uint8_t MASK_OTS = 0x01; // 温度过高
    static constexpr uint8_t MASK_AOCP = 0x02; // A通道过载
    static constexpr uint8_t MASK_BOCP = 0x04; // B通道过载
    static constexpr uint8_t MASK_APDF = 0x08; // A通道pre driver异常
    static constexpr uint8_t MASK_BPDF = 0x10; // B通道pre driver异常
    static constexpr uint8_t MASK_UVLO = 0x20; // 欠压锁定

/**
 * 驱动器1 A通道=>冰箱门电机
 *        B通道=>升降电机
 * 
 * 驱动器2 A通道=>机械臂电机1
 *        B通道=>机械臂电机2
 */

    uint16_t read1(uint8_t addr);
    uint16_t read2(uint8_t addr);
    void write1(uint8_t addr, uint16_t value);
    void write2(uint8_t addr, uint16_t value);

    inline uint16_t read_status1() { return read1(0x07); }
    inline uint16_t read_status2() { return read2(0x07); }

    inline void clear1() { write1(0x07, 0x00); }
    inline void clear2() { write2(0x07, 0x00); }

private:
    rtos::Mutex m_mutex;
};

inline utils::object_t<MotorDrv> motorDrv;

}

#endif
